<template>
  <div>
    <common-page
      ref="common"
      :ccode="ccode"
      @hook:created="commonCreated"
    />
    <h1>审批内容:</h1>
    <h2>xxxx</h2>
    <approve-history style="margin-top:10px;" :approval-list="approvalList" />
    <approve-cmd v-if="!loading" style="margin-top:10px;" :todo-info="todoInfo" :common-save="commonSave" @save="saveTodoForm" @submit="submitTodoForm" />
  </div>
</template>

<script>
import ApproveHistory from '@/components/WorkFlow/approveHistory.vue'
import ApproveCmd from '@/components/WorkFlow/approveCmd.vue'
import {
  invokeMethod
} from '@/api/common'
export default {
  name: 'WorkflowDemo',
  components: {
    ApproveHistory,
    ApproveCmd
  },
  data() {
    return {
      loading: true,
      todoInfo: {},
      approvalList: {}
    }
  },
  computed: {
    ccode: function() {
      return this.$route.meta.code
    },
    // 审批id
    parentDataId: function() {
      return this.$route.query.parentDataId || ''
    },
    // 业务id
    originalDataId: function() {
      return this.$route.query.originalDataId || ''
    }
  },
  mounted: function() {
    this.getTodoInfo()
  },
  methods: {
    commonSave() {
      return this.$form.saveForm(true)
    },
    commonCreated() {},
    // 获取代办事项
    getTodoInfo() {
      const params = {
        methodId: '773567309020139520',
        data: {
          oInsId: this.parentDataId
        }
      }
      invokeMethod(params).then(res => {
        this.todoInfo = res.data
        this.approvalList = res.data.approvalList
      }).finally(() => {
        this.loading = false
      })
    },
    saveTodoForm() {
      // 自定义保存,需要是Promise对象
      this.$form.saveForm(true).then(() => {
        this.$$success('保存成功')
      })
    },
    submitTodoForm() {
      // 自定义提交,需要是Promise对象
      this.$form.submitForm({
        done: () => {
          this.$form.redirectToParent()
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
div.is-approve ::v-deep .btn-container.actionbar{
  display: none;
}
div.is-approve ::v-deep .tool-container{
  text-align: center;
}
</style>
